home *** CD-ROM | disk | FTP | other *** search
- #ifndef lint
- static char SccsId[]= "@(#)slot_create.c V1.6 3/13/95";
- #endif
- /*
- | file name - slot_create.c
- |===================================================================
- |
- | This example shows how to attach data to objects using
- | the SLOT mechanism. In this example, we show how to create
- | SLOTs of the type OBJECT, STRING, and INT_ARRAY. We define
- | SLOTKEY objects for each of these types; create an empty
- | view; attach the data for each of these types to the drawing
- | in the view; and save the drawing to a file called "slot_temp.v"
- |
- | Note that in this example we are adding the slots to the drawing
- | object itself; you could just as easily add the slots to objects
- | in the drawing.
- |
- |===================================================================
- */
- #include <windows.h>
-
- #include "std.h"
- #include "dvstd.h"
- #include "dvtools.h"
- #include "VOstd.h"
- #include "Tfundecl.h"
- #include "VOfundecl.h"
-
- #define ARRAY_SIZE 3
-
- int iarray[ARRAY_SIZE] = {1, 2, 3};
- OBJECT object;
-
- int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
- LPSTR lpCmdLine, int nCmdShow )
- {
- VIEW view;
- OBJECT drawing;
- OBJECT iarraysk, namesk, objsk;
- OBJECT inobj;
- int *in_iarray;
- char *bufp;
- int argc;
- char **argv;
- char mes_str[100];
-
- make_argv(&argc,&argv,GetCommandLine());
- /* Initialize, creating an empty view */
- TInit ((char *) NULL, (char *) NULL); /* use DVPATH config var */
- view = TviCreate ();
- drawing = TviGetDrawing (view);
-
- /*--------------------------------------------------*/
- /* Define the SLOTKEY objects. */
- /* These define the data type and name of the slot. */
- /*--------------------------------------------------*/
- iarraysk = VOskDeclare ("V_INT_ARRAY", VOSK_INT_ARRAY_TYPE, ARRAY_SIZE);
- namesk = VOskDeclare ("V_STRING", VOSK_STRING_TYPE);
- objsk = VOskDeclare ("V_OBJECT", VOSK_OBJECT_TYPE);
-
- /* Create a rectangle to put in the object slot */
- object = VOreCreate ( VOptCreate ( WORLD_COORDINATES, -100, -100,
- (OBJECT) NULL),
- VOptCreate ( WORLD_COORDINATES, 100, 100,
- (OBJECT) NULL),
- (ATTRIBUTES *) NULL);
- VOobReference (object);
-
- /*--------------------------------------------------*/
- /* Add the slots to the drawing object. */
- /*--------------------------------------------------*/
- VOobSetSlot (drawing, iarraysk, (LONG *)iarray, (ULONG *) 0);
- VOobSetSlot (drawing, namesk, (LONG *)"Hello World", (ULONG *) 0);
- VOobSetSlot (drawing, objsk, (LONG *)&object, (ULONG *) 0);
-
- TviASCIISave (view, "slot_temp.v");
- TviDestroy (view);
-
- /*--------------------------------------------------------------*/
- /* Load the view that we just saved, and compare its slots to */
- /* the ones we just set */
- /*--------------------------------------------------------------*/
- view = TviLoad ("slot_temp.v");
- drawing = TviGetDrawing (view);
-
- /*---------------------------------------*/
- /* Retrieve the contents of each slot. */
- /*---------------------------------------*/
- VOobGetSlot (drawing, iarraysk, (LONG *)&in_iarray, (ULONG *) 0);
- VOobGetSlot (drawing, namesk, (LONG *)&bufp, (ULONG *) 0);
- VOobGetSlot (drawing, objsk, (LONG *)&inobj, (ULONG *) 0);
-
- /* Check the integer array slot */
- if (iarray[0] == in_iarray[0] &&
- iarray[1] == in_iarray[1] &&
- iarray[2] == in_iarray[2])
- sprintf ( mes_str,"INT ARRAY matched\n");
- else
- sprintf ( mes_str,"INT ARRAY did not match!!\n");
-
- /* Check the string slot */
- if (0 == strcmp ("Hello World", bufp))
- strcat( mes_str,"STRING matched\n");
- else
- strcat( mes_str,"STRING did not match!!\n");
-
- if (VOobType (object) == VOobType (inobj))
- strcat( mes_str,"OBJECT matched\n");
- else
- strcat( mes_str,"OBJECT did not match!!\n");
-
- MessageBox (
- GetFocus (),
- mes_str,
- "slot_create:",
- MB_OK
- );
-
- TviDestroy (view);
- TTerminate ();
- return (EXIT_OK);
- }
-